<%
local function get_speederv2_version(name)
	local info = luci.util.split(luci.sys.exec("%s -h 2>/dev/null" %{name}), "\n")
	local version = string.match(info[2], "git version: (%w+)")
	local build = string.match(info[2], "build date: (.+)")
	return info[1] == "UDPspeeder V2" and version or "", info[1] == "UDPspeeder V2" and build or ""
end

local speederv2_version, speederv2_build = get_speederv2_version("speederv2")
-%>

<fieldset class="cbi-section">
	<legend><%:Running Status%></legend>
	<table width="100%" cellspacing="10" id="_speederv2_status_table">
		<tr>
			<td width="33%"><%:Binary Version%></td>
			<td>
				<% if speederv2_version == "" then -%>
				<em><%:Invalid Binary File.%></em>
				<% else -%>
				<%=pcdata(speederv2_version)%>
				<%- end %>
			</td>
		</tr>
		<% if speederv2_build ~= "" then -%>
		<tr><td width="33%"><%:Build Time%></td><td><%=pcdata(speederv2_build)%></td></tr>
		<% end -%>
		<tr><td width="33%"><%:Running Status%></td><td id="_speederv2_status"><em><%:Collecting data...%></em></td></tr>
	</table>
</fieldset>

<script type="text/javascript">//<![CDATA[
	var speederv2_status = document.getElementById('_speederv2_status');
	XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "services", "speederv2", "status")%>', null, function(x, status) {
		if ( x && x.status == 200 ) {
			speederv2_status.innerHTML = status.running ? '<%:RUNNING%>' : '<%:NOT RUNNING%>';
		}
	});
//]]></script>
